***************** Replication of Franchino, Fabio, and Camilla Mariotto. “Bargaining Outcomes and Success in EU Economic Governance Reforms”. Political Science Research and Methods.

* Step 1 to reproduce Figure A4

version 16

******************************* SENSITIVITY ANALYSIS
*************   COMPUTING POINT PREDICTIONS: Minimax Model  (10% selected)
clear all
gen mad=.
save mad_minimax.dta, replace

set seed 1234

local v = 0
while `v' <= 1000 {
* Upload original dataset
use NBSmodel_data.dta, clear
gen minimax = .
gen disutility_max = .

* Modify 20% of actors's positions
/* We test for unsystematic mis-categorization following the re-categorization test proposed by Eric Neumayer and Thomas Plümper.
We have drawn a random sample of twenty percent of the positions. We have then increased by 25 points the position for half of these cases (if it is not located on upper bound) and decreased by 25 points the other half (if it is not located on the lower bound).
We have then estimated the model outcomes. The procedure is repeated for 1,000 samples
*/
***** Select a random sample without replacement of observations
***** change 4 out of 35 obs
generate random = runiform()
sort random
do meaningful_shift_comm.do
drop random

generate random = runiform()
sort random
do meaningful_shift_ep_1.do
drop random

do meaningful_shift_country.do

* Gradient ascent procedure
local p = 0
while `p' <= 100 {
gen minimax_p = `p'
gen disutility_p=0
order minimax* disutility*
* compute maximum disutility of actors for p=`p'
local c = 1
while `c' <= 27 {
gen utility`c' =	salience`c'	*(`p' -	country`c')^2 if	salience`c'	> 0 &	salience`c'	!= .
replace disutility_p = utility`c' if utility`c' > disutility_p & utility`c' != .
local c = `c' + 1
}
gen utility_comm =	salience_comm	*(`p' -	comm	)^2 if	salience_comm	> 0 &	salience_comm	!= .
replace disutility_p = utility_comm if utility_comm > disutility_p
gen utility_ep =	salience_ep	*(`p' -	ep_1)^2 if	salience_ep	> 0 &	salience_ep	!= .
replace disutility_p = utility_ep if utility_ep > disutility_p & ep_rule==2

* replace minimax and disutility
replace minimax = minimax_p if `p'==0
replace disutility_max = disutility_p if `p'==0

replace minimax = minimax_p if  disutility_p < disutility_max
replace disutility_max = disutility_p if  disutility_p < disutility_max
order minimax* disutility* utility_comm utility_ep utility*
drop minimax_p* disutility_p* utility*
local p = `p' + 1
}

order disutility_max minimax sq outcome
sort act issue_id
label variable minimax "mimax solution"
label variable disutility_max "maximum utility loss" 

* Compute means of absolute differences between outcomes and model predictions
gen mad=abs(minimax-outcome)
collapse mad
label variable mad "mean of absolute differences" 
append using mad_minimax.dta
save mad_minimax.dta, replace
sleep 200
local v = `v' + 1
}

use mad_minimax.dta, clear
mean mad
kdensity mad, nor normopts(lwidth(vvthin)) graphregion(fcolor(white)) legend(off) ytitle("") xtitle("") text(0.75 26 "mean 30.6" "s.e. 0.02", si(small) place(e)) title("Minimax", si(small)) note("") ylabel(,labsize(small)) xlabel(,labsize(small)) saving(minimax, replace)

